package com.yanqu.road.server.cmd.patrons;

import com.yanqu.road.logic.pb.PatronsPb;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_PATRONS_STAGE, desc = "门客精进")
public class PatronsStageCmd extends AbstractCommand {

	private int patronsId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		PatronsProto.PatronsStageReqMsg reqMsg = PatronsProto.PatronsStageReqMsg.parseFrom(packet.getBytes());
		patronsId = reqMsg.getPatronsId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(PatronsModule.class).patronsStage(patronsId);
	}

	@Override
	public void sendData(GamePlayer player) {
		PatronsProto.PatronsStageRespMsg.Builder respMsg = PatronsProto.PatronsStageRespMsg.newBuilder();
		respMsg.setRet(ret);
		UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(patronsId);
		PatronsProto.PatronsTempMsg.Builder patronsMsg = PatronsPb.parsePatronsTempMsg(userPatrons);
		if(null != patronsMsg) {
			respMsg.setPatrons(patronsMsg);
		}
		player.sendPacket(Protocol.U_PATRONS_STAGE, respMsg);
	}
}
